$(function(){
	var admin_id = getCookie('admin_id');
	if(!admin_id){
		window.location.replace('login.html');
	}
	var admin_name=getCookie('real_name');
	//左侧导航
	var menu_list=getCookie('menu');
	var strs= new Array(); //定义一数组

	strs=menu_list.split(","); //字符分割
	// console.log(strs);
	var html='<li class="nav-header">'
                +'<div class="dropdown profile-element">'
                    +'<a data-toggle="dropdown" class="dropdown-toggle" href="#">'
                        +'<span class="clear">'
                            +'<span class="block m-t-xs" style="font-size:20px;">'
                                +'<i class="fa fa-area-chart"></i>'
                                +'<strong class="font-bold">'+admin_name+'</strong>'
                            +'</span>'
                        +'</span>'
                    +'</a>'
                +'</div>'
                +'<div class="logo-element">hAdmin</div>'
            +'</li>';
	for (i=0;i<strs.length ;i++ ) 
	{ 
		if(strs[i]){
			if(strs[i].indexOf("&") > 0 ){
			var menu=strs[i].split("&");
			for (j=0;j<menu.length;j++) {
				var menu_info=menu[j].split("/");
				if(j <1){
					html +='<li class="hidden-folded padder m-t m-b-sm text-muted text-xs">'
			                   +'<span class="ng-scope">'+menu_info[1]+'</span>'
			              +'</li>';
				}else{
					html +='<li>'
		                      +'<a class="J_menuItem" href="'+menu_info[2]+'.html">'
		                          +'<i class="fa fa-'+menu_info[3]+'"></i>'
		                          +'<span class="nav-label">'+menu_info[1]+'</span>'
		                      +'</a>'
		                  +'</li>';
				}	
			}
		}else{
			var menu_info=strs[i].split("/");
			html +='<li class="hidden-folded padder m-t m-b-sm text-muted text-xs">'
                    +'<span class="ng-scope">'+menu_info[1]+'</span>'
                 +'</li>';
		}	
		}
	}
	$("#side-menu").html(html);
    //菜单点击
    J_iframe
    $(".J_menuItem").on('click',function(){
        var url = $(this).attr('href');
        $("#J_iframe").attr('src',url);
        return false;
    });
});


$(function(){
	$(".logout").click(function () {
		$.ajax({
			url: ApiUrl + "/logout",
			type: 'GET',
			data: '',
			dataType: 'JSON',
			success: function(result) {
				if(result.code == 200){
					//存储店员信息
					delCookie('admin_id');
					delCookie('admin_uid');
					delCookie('real_name');
					delCookie('avatar');
					delCookie('sex');
					delCookie('store_id');
					delCookie('status');
					delCookie('created_at');
					delCookie('token');
					delCookie('menu');
					window.location.replace('login.html');
				}else{
					parent.layer.msg(result.message);
					return false;
				}
			}
		});
	})
});